/*
 * Copyright 2016-2017 TVI Go Easy.
 * Created on 2017/5/1 11:15
 */
package org.mechanic.fund.service.wechat.impl;

import org.mechanic.fund.domain.system.manager.Department;
import org.mechanic.fund.domain.utils.mapper.DtoBeanMapper;
import org.mechanic.fund.repository.wechat.WcDepartmentRepository;
import org.mechanic.fund.service.wechat.IWcAccessApiService;
import org.mechanic.fund.service.wechat.IWcDepartmentService;
import org.mechanic.utils.collection.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Map;

/**
 * 部门信息服务接实现
 *
 * @author mechanic
 * @version 0.0.1
 */
@Service
public class WcDepartmentService implements IWcDepartmentService {

    private final WcDepartmentRepository repository;
    private final IWcAccessApiService apiService;

    @Autowired
    public WcDepartmentService(WcDepartmentRepository repository, IWcAccessApiService apiService) {
        this.repository = repository;
        this.apiService = apiService;
    }

    /**
     * 保存部门信息
     *
     * @param department      角色信息集合
     * @param operationUserId 操作该记录的用户主键编号
     */
    @Override
    @Transactional
    public void save(Department department, String operationUserId) {
        Department saved = this.repository.save(DtoBeanMapper.setOperationToDomain(department, operationUserId));
        Map<String, String> wcDepartment = MapUtil.emptyMap();
        wcDepartment.put("id", department.getId());
        wcDepartment.put("name", department.getName());
        wcDepartment.put("parentid", department.getWxParent().getId());
        wcDepartment.put("order", department.getSort().toString());
        //this.apiService.saveDepartment(department);
    }
}
